function sayName () {
  console.log('my name is', this.name)
}
// 定义一个Person的构造函数
function Person (name, age, gender) {
  this.name = name;
  this.age = age;
  this.gender = gender;
  // 第二种内存空间一样
  this.sayName = sayName;
  // 第一种内存空间不一样
  // this.sayName = function () {
  //   console.log('my name is', this.name)
  // }
}
// 定义一个Dog的构造函数
function Dog (name, age, gender) {
  this.name = name;
  this.age = age;
  this.gender = gender;
  this.sayName = function () {
    console.log('my name is', this.name)
  }
}
// 使用构造函数
var p1 = new Person('zhangsan', 12, 'male')
// console.log(p1);
// p1.sayName()
var p2 = new Person('lisi', 12, 'male')
// console.log(p2);
// p2.sayName()
var d1 = new Dog('erha', 2, 'male')
// console.log(d1);
// d1.sayName()

console.log(p1.sayName === p2.sayName);

// Person('WANGWU', 16, 'male')

// console.log(p1 instanceof Person);
// console.log(d1 instanceof Dog);
// console.log(d1 instanceof Person);